package com.hdrx.fundhelper.utils;

import com.itextpdf.text.pdf.PdfReader;
import com.itextpdf.text.pdf.parser.PdfTextExtractor;

import java.io.IOException;

/**
 * @author: houdx
 * @description:
 * @date: 2023/7/13 16:28
 */
public class PdfUtil {
    /**
     * 读取pdf文件的内容
     * @param filename  F:/data/aet618.pdf
     * @return  String
     */
    public static String readPDF(String filename){
        StringBuilder result = new StringBuilder();
        try {
            PdfReader reader = new PdfReader(filename);
            int countPage = reader.getNumberOfPages();
            for(int i=1;i<=countPage;i++){
                result.append(PdfTextExtractor.getTextFromPage(reader, i));
            }
            reader.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return result.toString();
    }


    public static void main(String[] args) {
        //String txtPath = "E:/test617.txt";
        String pdfPath = "E:\\1\\123.pdf";
        String s = PdfUtil.readPDF(pdfPath);
        System.out.println(s);

        String s2 = s.substring(s.indexOf(" "),s.indexOf("6"));

        System.out.println(">>>>>>>s2>>>>>>>>>"+s2);
        String[] split = s2.split("：");
        for (int i = 0; i < split.length; i++) {
            System.out.println(split[i]);
        }

    }
}
